//
//  RCLoginDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-7-1.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCLoginDataModel.h"
#import "TravelException.h"
#import "KFObjectExtension.h"

@implementation RCLoginDataModel

@synthesize nickName;
@synthesize bduss;
@synthesize signinCount;
@synthesize reviewCount;
@synthesize photosCount;

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCLoginDataModel *retObject = nil;
    retObject = [[RCLoginDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];

    
    retObject.errorNO = [data intValueForKey:@"errno" defaultValue:-1];
    retObject.errorMsg = [data stringValueForKey:@"msg"
                                    defaultValue:@""
                                       operation:NSStringOperationTypeTrim];
    
    NSDictionary *dic = [data dictObjectForKey:@"data" withDefaultValue:nil];
    retObject.bduss = [dic stringValueForKey:@"bduss" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.nickName = [dic stringValueForKey:@"username" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.signinCount = [dic intValueForKey:@"signin" defaultValue:0];
    retObject.reviewCount = [dic intValueForKey:@"review" defaultValue:0];
    retObject.photosCount = [dic intValueForKey:@"photo" defaultValue:0];

    return [retObject autorelease];
}

@end


@implementation RCServerLoginDataModel

@synthesize cityid = _cityid;
@synthesize cityname = _cityname;
@synthesize memberbduss = _memberbduss;
@synthesize shopbduss = _shopbduss;
@synthesize shopid    = _shopid;
@synthesize shopname  = _shopname;
@synthesize username  = _username;
+(id)parseDataFromJSON:(NSDictionary *)data
{
    if (nil == data) {
        return nil;
    }
    RCServerLoginDataModel *retObject = nil;
    retObject = [[[RCServerLoginDataModel alloc]init] autorelease];

    NSDictionary *dic = [data dictObjectForKey:@"data" withDefaultValue:nil];

    retObject.cityid = [dic stringValueForKey:@"cityid" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.cityname = [dic stringValueForKey:@"cityname" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.memberbduss = [dic stringValueForKey:@"memberbduss" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.shopbduss = [dic stringValueForKey:@"shopbduss" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.shopid = [dic stringValueForKey:@"shopid" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.shopname = [dic stringValueForKey:@"shopname" defaultValue:@"" operation:NSStringOperationTypeNone];
    retObject.username = [dic stringValueForKey:@"username" defaultValue:@"" operation:NSStringOperationTypeNone];

    return retObject;
}
@end

@implementation RCBalanceDataModel
@synthesize balance;

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCBalanceDataModel *retObject = nil;
    retObject = [[RCBalanceDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];
    NSDictionary *dic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.balance = [dic stringValueForKey:@"balance" defaultValue:nil operation:NSStringOperationTypeNone];

    
    return [retObject autorelease];
}


@end


@implementation RCCostListDataModel


+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCCostListDataModel *retObject = nil;
    retObject = [[RCCostListDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];
    NSDictionary *dic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dic intValueForKey:@"total" defaultValue:0];

    NSMutableArray *itemsArray = [[NSMutableArray alloc] init];
    NSArray *listItems = [dic arrayObjectForKey:@"list" withDefaultValue:nil];
    for (NSDictionary *dic in listItems) {
        RCCostItemDataModel *item = [[RCCostItemDataModel alloc] initWithDic:dic];
        [itemsArray addObject:item];
        [item release];
    }
    retObject.listItems = itemsArray;
    
    [itemsArray release];
    
    return [retObject autorelease];
}
@end


@implementation RCCostItemDataModel
@synthesize consume_addr = _consume_addr;
@synthesize consume_count= _consume_count;
@synthesize consume_date = _consume_date;
@synthesize consume_extra = _consume_extra;
@synthesize consume_name = _consume_name;
@synthesize consume_phone = _consume_phone;
@synthesize consume_state = _consume_state;

- (id) initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.consume_addr = [dic stringValueForKey:@"shopname" defaultValue:nil operation:NSStringOperationTypeTrim];
//        self.consume_count = [dic stringValueForKey:@"consume_count" defaultValue:nil operation:NSStringOperationTypeNone];
        self.consume_name = [dic stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeTrim];
        self.consume_state = [dic stringValueForKey:@"status" defaultValue:nil operation:NSStringOperationTypeTrim];
        self.consume_phone = [dic stringValueForKey:@"mobile" defaultValue:nil operation:NSStringOperationTypeTrim];
        self.consume_extra = [dic stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
        if (nil == self.consume_extra || [self.consume_extra isEqualToString:@""]) {
            self.consume_extra = @"无";
        }
        
        NSTimeInterval timeInterval = [dic doubleValueForKey:@"datetime" defaultValue:0];
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        formatter.dateFormat = @"yyyy-MM-dd hh:mm";
        NSString *dateStr = [formatter stringFromDate:date];
        [formatter release];
        self.consume_date = dateStr;

    }
    return self;
}

- (void) dealloc
{
    self.consume_date = nil;
    self.consume_count= nil;
    self.consume_addr = nil;
    self.consume_state = nil;
    self.consume_phone = nil;
    self.consume_name = nil;
    self.consume_extra = nil;
    [super dealloc];
}
@end
